package com.atguigu.gmall.mq.controller;

import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayedMqConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发消息
 */
@RestController
@RequestMapping("/api/mq")
public class SendMessageController {
    @Autowired
    private RabbitService rabbitService;//SSM框架 Spring框架

    // 动态代理
    //1: JDK动态代理     @Autowired注入的是接口 使用
    //2: CgLib动态代理    @Autowired注入是实现类
    //发消息
    @GetMapping("/send/{message}")
    public Result send(@PathVariable String message){
        rabbitService.sendMessage("exchange123","routingKey123",message);
        return Result.ok();
    }

    //发基于死信的延迟消息
    @GetMapping("/sendDeadLetterMessage/{message}")
    public Result senDeadLetterMessage(@PathVariable String message){
        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,message,13);
        return Result.ok();
    }

    //发基于插件的死信延迟消息
    @GetMapping("/sendDelayMessage/{message}")
    public Result sendDelayMessage(@PathVariable String message){
        rabbitService.sendDelayMessage(DelayedMqConfig.exchange_delay,DelayedMqConfig.routing_delay,message,11);
        return Result.ok();
    }
}
